<?php

namespace app\admin\controller;
use think\facade\Env;
use think\Request;
class File
{
    public function upload(){
		$newpath = date('Y/m/d',time());
		$rootpath = Env::get('app_path').'../public/static/upload/'.$newpath;

		if(!file_exists($rootpath)) mkdir($rootpath,0777,true);

		$filename = $_FILES['file']['name'];

		$ar = explode('.',$filename);
		$ext = $ar[count($ar)-1];
		if(in_array($ext,['php','asp','aspx','jsp','html'])){
			return false;
		}
		$titname = substr($filename,0,strlen($filename)-strlen($ext)-1);

		$newname = time().'-'.md5($_FILES['file']['name']);
		move_uploaded_file($_FILES['file']['tmp_name'], $rootpath.'/'.$newname.'.'.$ext);
		//$domain = $dobj['domain']?'http://'.$dobj['domain']:'';
		return [
			'name'=>$_FILES['file']['name'],
			'title'=>$titname,
			'src'=>'/static/upload/'.$newpath.'/'.$newname.'.'.$ext,
			'path'=>'/static/upload/'.$newpath.'/'.$newname.'.'.$ext
		];
    }
}
